var prefs__MODULE_ID__;
var items__MODULE_ID__;
var edited__MODULE_ID__;

function Item__MODULE_ID__(name, month, day) {
	this.name = name;
	this.month = month;
	this.day = day;
	this.priority = 2;
}

function loadItems__MODULE_ID__() {
	var itemstring;
	itemstring = prefs__MODULE_ID__.getString("items");
	itemstring = gadgets.util.unescapeString(itemstring);
	if (itemstring === "") {
		items__MODULE_ID__ = [];
	}
	else {
		items__MODULE_ID__ = gadgets.json.parse(itemstring);
	}
}

function numItems__MODULE_ID__() {
	return items__MODULE_ID__.length;
}

function compareDate__MODULE_ID__(a, b) {
	var today, thisMonth, thisDay, monthA, dateA, monthB, dateB;
	today = new Date();
	thisMonth = today.getMonth() + 1;
	thisDay = today.getDate();
	monthA = a.month;
	if (monthA === 0) {
		monthA = 99;
	}
	else {
		monthA -= thisMonth;
	}
	if (monthA < 0) {
		monthA += 12;
	}
	dateA = (100 * monthA) + a.day;
	monthB = b.month;
	if (monthB === 0) {
		monthB = 99;
	}
	else {
		monthB -= thisMonth;
	}
	if (monthB < 0) {
		monthB += 12;
	}
	dateB = (100 * monthB) + b.day;          
	if (dateA === dateB) {
		return 0;
	}
	else if (dateA > dateB) {
		return 1;
	}
	else if (dateA < dateB) {
		return -1;
	}
}

function sortByDate__MODULE_ID__() {
	items__MODULE_ID__.sort(compareDate__MODULE_ID__);
}

function saveItems__MODULE_ID__() {
	prefs__MODULE_ID__.set("items", gadgets.json.stringify(items__MODULE_ID__));
	document.getElementById("newItemInput__MODULE_ID__").focus();
}

function comparePriority__MODULE_ID__(a, b) {
	if (a.priority === b.priority) {
		return 0;
	}
	else if (a.priority > b.priority) {
		return 1;
	}
	else if (a.priority < b.priority) {
		return -1;
	}
}

function sortByPriority__MODULE_ID__() {   
	items__MODULE_ID__.sort(comparePriority__MODULE_ID__);
}

function compareName__MODULE_ID__(a, b) {
	if (a.name === b.name) {
		return 0;
	}
	else if (a.name > b.name) {
		return 1;
	}
	else if (a.name < b.name) {
		return -1;
	}
}

function sortByName__MODULE_ID__() {
	items__MODULE_ID__.sort(compareName__MODULE_ID__);
}

function createPriorityTopLink__MODULE_ID__() {
	var html = "<td class=priorityTopLink__MODULE_ID__><a href=\"javascript:changeSort__MODULE_ID__(1)\">__MSG_priority__</a></td>"; 
	return html;
}
		
function createNameTopLink__MODULE_ID__() {
	var html = "<td class=nameTopLink__MODULE_ID__><a href=\"javascript:changeSort__MODULE_ID__(2)\">__MSG_name__</a></td>"; 
	return html;
}
		
function createDateTopLink__MODULE_ID__() {
	var html = "<td class=dateTopLink__MODULE_ID__><a href=\"javascript:changeSort__MODULE_ID__(3)\">__MSG_date__</a></td>"; 
	return html;
}

function rowClass__MODULE_ID__(number) {
	if (number % 2 !== 0) {
		return " class=odd__MODULE_ID__ ";
	}
	else {
		return " class=even__MODULE_ID__ ";
	}
}

function getPriorityText__MODULE_ID__(priority) {
	if (priority === 1) {
		return "__MSG_high__";
	}
	else if (priority === 2) {
		return "__MSG_medium__";
	}
	return "__MSG_low__";
}

function createPriorityLink__MODULE_ID__(index, priority) {
	var html =
		"<a class=p" + priority + "__MODULE_ID__ " +
		"href=\"javascript:editPriority__MODULE_ID__(" +
		index + "," + priority + ")\">" +
		getPriorityText__MODULE_ID__(priority) +
		"</a>";
	return html;
}
		
function createMonthLink__MODULE_ID__(index, month) {
	var value, html;
	value = parseInt(month);
	if (value === 0) {
		value = "N";
	}
	html =
		"<a class=date_link__MODULE_ID__ href=\"javascript:editMonth__MODULE_ID__(" + index + "," + month + ")\">" + value + "</a>";
	return html;
}
		
function createDayLink__MODULE_ID__(index, day) {
	var value, html;
	value = parseInt(day);
	if (value === 0) {
		value = "A";
	}
	html =
		"<a class=date_link__MODULE_ID__ href=\"javascript:editDay__MODULE_ID__(" + index + "," + day + ")\">" + value + "</a>";
	return html;
}

function escapeName__MODULE_ID__(name) {
	name = name.replace(/&/g, "&#38;");
	name = name.replace(/</g, "&#60;");
	name = name.replace(/>/g, "&#62;");
	name = name.replace(/"/g, "&#34;");
	name = name.replace(/'/g, "&#39;");
	return name;
}

function createName__MODULE_ID__(index, name) {
	var html =
		"<a class=name_a__MODULE_ID__" +
		" href=\"javascript:editName__MODULE_ID__(" +  index + ")\">" +
		escapeName__MODULE_ID__(name) +
		"</a>";
	return html;
}

function createDelete__MODULE_ID__(index) {
	var html =
		"<a href=\"javascript:deleteItem__MODULE_ID__(" + index + ")\">" +
		"<img class=delete__MODULE_ID__" +
		" src=\"http://www.google.com/ig/modules/todo_content/x.gif\">" +
		"</a>";
	return html;
}

function createRow__MODULE_ID__(index, item) {
	var html =
		"<tr id=\"row" + index + "__MODULE_ID__\"" +
		rowClass__MODULE_ID__(index) + ">" +
		"<td class=priority_td__MODULE_ID__>" +
		createPriorityLink__MODULE_ID__(index, item.priority) +
		"</td>" +
		"<td class=name_td__MODULE_ID__>" +
		createName__MODULE_ID__(index, item.name) +
		"</td>" +
		"<td class=date_td__MODULE_ID__>" +
		createMonthLink__MODULE_ID__(index, item.month) + "/" + createDayLink__MODULE_ID__(index, item.day) + 
		"</td>" +
		"<td>" +
		createDelete__MODULE_ID__(index) +
		"</td>" +
		"</tr>";            
	return html;
}

function createTable__MODULE_ID__() {
	var html, i, priority, name, month, day;
	if (prefs__MODULE_ID__.getString("sort") === "date") {
		sortByDate__MODULE_ID__();
	}
	else if (prefs__MODULE_ID__.getString("sort") === "name") {
		sortByName__MODULE_ID__();
	}
	else {
		sortByPriority__MODULE_ID__();
	}
		
	html = "<table width=\"100%\" cellspacing=0 id=topLinksTable__MODULE_ID__>";
	html += "<tr width=\"100%\">" + createPriorityTopLink__MODULE_ID__() +
		createNameTopLink__MODULE_ID__() + createDateTopLink__MODULE_ID__() + "</tr>";
	html += "</table><table cellspacing=0 id=itemsTable__MODULE_ID__>";
	for (i = 0; i < numItems__MODULE_ID__(); i += 1) {
		priority = items__MODULE_ID__[i].priority;
		name = items__MODULE_ID__[i].name;
		month = items__MODULE_ID__[i].month;
		day = items__MODULE_ID__[i].day;
		html += createRow__MODULE_ID__(i, items__MODULE_ID__[i]);
	}
	html += "</table>";
	document.getElementById("itemsDiv__MODULE_ID__").innerHTML = html;
	gadgets.window.adjustHeight();
}

function addItem__MODULE_ID__(name, month, day) {
	document.getElementById("newItemInput__MODULE_ID__").value = "";
	document.getElementById("monthPicker__MODULE_ID__").value = "0";
	document.getElementById("dayPicker__MODULE_ID__").value = "0";
	if (name === "") {
		return;
	}
	items__MODULE_ID__[numItems__MODULE_ID__()] = new Item__MODULE_ID__(name, month, day);
	createTable__MODULE_ID__();
	saveItems__MODULE_ID__();
	return false;
}

function deleteItem__MODULE_ID__(number) {
	var beginning, end;
	if (edited__MODULE_ID__) {
		return;
	}
	beginning = items__MODULE_ID__.slice(0, number);
	end = items__MODULE_ID__.slice(number + 1, numItems__MODULE_ID__());
	items__MODULE_ID__ = beginning.concat(end);
	createTable__MODULE_ID__();
	saveItems__MODULE_ID__();
}

function swapItems__MODULE_ID__(to, from) {
	var temp = items__MODULE_ID__[to];
	items__MODULE_ID__[to] = items__MODULE_ID__[from];
	items__MODULE_ID__[from] = temp;
}

function getRow__MODULE_ID__(number) {
	return document.getElementById("row" + number + "__MODULE_ID__");
}

function getCol__MODULE_ID__(row, index) {
	return row.childNodes.item(index);
}

function setPriority__MODULE_ID__(number, priority) {
	var row, col;
	priority = parseInt(priority);
	row = getRow__MODULE_ID__(number);
	col = getCol__MODULE_ID__(row, 0);
	col.innerHTML = createPriorityLink__MODULE_ID__(number, priority);
	items__MODULE_ID__[number].priority = priority;
	createTable__MODULE_ID__();
	saveItems__MODULE_ID__();
}

function selected__MODULE_ID__(value, num) {
	if (value === num) {
		return "selected=true";
	}
	else {
		return "";
	}
}

function createPrioritySelect__MODULE_ID__(number, priority) {
	var html =
		"<select id=select__MODULE_ID__ " +
		"onchange=\"submitPriority__MODULE_ID__(" + number + ")\">" +
		"<option class=option__MODULE_ID__ value=1 " +
		"onclick=\"submitPriority__MODULE_ID__(" + number + ")\" " +
		selected__MODULE_ID__(priority, 1) + ">" +
		"__MSG_high__" +
		"</option>" +
		"<option class=option__MODULE_ID__ value=2 " +
		"onclick=\"submitPriority__MODULE_ID__(" + number + ")\" " +
		selected__MODULE_ID__(priority, 2) + ">" +
		"__MSG_medium__" +
		"</option>" +
		"<option class=option__MODULE_ID__ value=3 " +
		"onclick=\"submitPriority__MODULE_ID__(" + number + ")\" " +
		selected__MODULE_ID__(priority, 3) + ">" +
		"__MSG_low__" +
		"</option>" +
		"</select>";
	return html;
}

function editPriority__MODULE_ID__(number, priority) {
	var row, col;
	row = getRow__MODULE_ID__(number);
	if (edited__MODULE_ID__) {
		return;
	}
	edited__MODULE_ID__ = true;
	col = getCol__MODULE_ID__(row, 0);
	col.innerHTML = createPrioritySelect__MODULE_ID__(number, priority);
}

function changeSort__MODULE_ID__(type) {    
	if (type === 1) {
		prefs__MODULE_ID__.set("sort", "priority");
	}
	else if (type === 2) {
		prefs__MODULE_ID__.set("sort", "name");
	}
	else {
		prefs__MODULE_ID__.set("sort", "date");
	}
	createTable__MODULE_ID__();
}

function createDate__MODULE_ID__(number, month, day) {  
	if (month === 0) {
		month = "N";
	}
	else { 
		month = createMonthLink__MODULE_ID__(number, month);
	}
	if (day === 0) {
		day = "A";
	}
	else {
		day = createDayLink__MODULE_ID__(number, day);
	}
	var html = month + "/" + day;
	return html;
}

function createMonthSelect__MODULE_ID__(number, month) {
	var html =
		"<select class=monthPicker__MODULE_ID__ id=monthSelect__MODULE_ID__ onchange=\"submitMonth__MODULE_ID__(" + number + ")\">" + 
		"<option value=0 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 0) + ">-</option>" +
		"<option value=1 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 1) + ">1</option>" +
		"<option value=2 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 2) + ">2</option>" +
		"<option value=3 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 3) + ">3</option>" +
		"<option value=4 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 4) + ">4</option>" +
		"<option value=5 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 5) + ">5</option>" +
		"<option value=6 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 6) + ">6</option>" +
		"<option value=7 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 7) + ">7</option>" +
		"<option value=8 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 8) + ">8</option>" +
		"<option value=9 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 9) + ">9</option>" +
		"<option value=10 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 10) + ">10</option>" +
		"<option value=11 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" +
		selected__MODULE_ID__(month, 11) + ">11</option>" +
		"<option value=12 onclick=\"submitMonth__MODULE_ID__(" + number + ")\"" + 
		selected__MODULE_ID__(month, 12) + ">12</option>" +
		"</select>";
	return html;
}

function setMonth__MODULE_ID__(number, month) {
	var row, col;
	row = getRow__MODULE_ID__(number);
	col = getCol__MODULE_ID__(row, 2);
	col.innerHTML = (createMonthLink__MODULE_ID__(number, month) + "/" +
		createDayLink__MODULE_ID__(number, items__MODULE_ID__[number].day));
	items__MODULE_ID__[number].month = month;
	createTable__MODULE_ID__();
	saveItems__MODULE_ID__();
}

function submitMonth__MODULE_ID__(number) {
	var row, col, select, newMonth;
	row = getRow__MODULE_ID__(number);
	col = getCol__MODULE_ID__(row, 2);
	select = document.getElementById("monthSelect__MODULE_ID__");
	newMonth = select.options[select.selectedIndex].value;
	setMonth__MODULE_ID__(number, newMonth);
	edited__MODULE_ID__ = false;
}

function editMonth__MODULE_ID__(number, month) {
	var row, col;
	row = getRow__MODULE_ID__(number);
	if (edited__MODULE_ID__) {
		return;
	}
	edited__MODULE_ID__ = true;
	col = getCol__MODULE_ID__(row, 2);
	col.innerHTML = (createMonthSelect__MODULE_ID__(number, month) + "/" +
		createDayLink__MODULE_ID__(number, items__MODULE_ID__[number].day));
}

function createDaySelect__MODULE_ID__(number, day) {
	var html, today, year, month;
	html = "<select class=dayPicker__MODULE_ID__ id=daySelect__MODULE_ID__ onchange=\"submitDay__MODULE_ID__(" + number + ")\">" + 
		"<option value=0 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 0) + ">-</option>";
	if (items__MODULE_ID__[number].month > 0) {
		html += "<option value=1 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 1) + ">1</option>" +
			"<option value=2 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 2) + ">2</option>" +
			"<option value=3 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 3) + ">3</option>" +
			"<option value=4 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 4) + ">4</option>" +
			"<option value=5 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 5) + ">5</option>" +
			"<option value=6 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 6) + ">6</option>" +
			"<option value=7 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 7) + ">7</option>" +
			"<option value=8 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 8) + ">8</option>" +
			"<option value=9 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 9) + ">9</option>" +
			"<option value=10 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 10) + ">10</option>" +
			"<option value=11 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 11) + ">11</option>" +
			"<option value=12 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 12) + ">12</option>" +
			"<option value=13 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 13) + ">13</option>" +
			"<option value=14 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 14) + ">14</option>" +
			"<option value=15 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 15) + ">15</option>" +
			"<option value=16 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 16) + ">16</option>" +
			"<option value=17 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 17) + ">17</option>" +
			"<option value=18 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 18) + ">18</option>" +
			"<option value=19 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 19) + ">19</option>" +
			"<option value=20 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 20) + ">20</option>" +
			"<option value=21 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 21) + ">21</option>" +
			"<option value=22 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 22) + ">22</option>" +
			"<option value=23 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 23) + ">23</option>" +
			"<option value=24 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 24) + ">24</option>" +
			"<option value=25 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 25) + ">25</option>" +
			"<option value=26 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 26) + ">26</option>" +
			"<option value=27 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 27) + ">27</option>" +
			"<option value=28 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" + selected__MODULE_ID__(day, 28) + ">28</option>";
	}
	today = new Date();
	year = today.getYear();
	month = items__MODULE_ID__[number].month;
	if (typeof (month) === "string") {
		month = parseInt(month);
	}
	if (month === 2 && year % 4 === 0) {
		html += "<option value=29 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" +  
			selected__MODULE_ID__(day, 29) +  ">29</option>";
	}
	if (month !== 2  && month !== 0) {
		html += "<option value=29 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" +
			selected__MODULE_ID__(day, 29) +  ">29</option>" +
			"<option value=30 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" +  
			selected__MODULE_ID__(day, 30) +  ">30</option>";
	}
	if (month === 1 || month === 3 || month === 5 || month === 7 || 
		month === 8 || month === 10 || month === 12) {
		html += "<option value=31 onclick=\"submitDay__MODULE_ID__(" + number + ")\"" +  
			selected__MODULE_ID__(day, 31) +  ">31</option>";
		html += "</select>";
	}
	return html;
}

function setDay__MODULE_ID__(number, day) {
	var row, col;
	row = getRow__MODULE_ID__(number);
	col = getCol__MODULE_ID__(row, 2);
	col.innerHTML = (createMonthLink__MODULE_ID__(number, items__MODULE_ID__[number].month) + "/" +
		createDayLink__MODULE_ID__(number, day));
	items__MODULE_ID__[number].day = day;
	createTable__MODULE_ID__();
	saveItems__MODULE_ID__();
}

function submitDay__MODULE_ID__(number) {
	var row, col, select, newDay;
	row = getRow__MODULE_ID__(number);
	col = getCol__MODULE_ID__(row, 2);
	select = document.getElementById("daySelect__MODULE_ID__");
	newDay = select.options[select.selectedIndex].value;
	setDay__MODULE_ID__(number, newDay);
	edited__MODULE_ID__ = false;
}

function editDay__MODULE_ID__(number, day) {
	var row, col;
	row = getRow__MODULE_ID__(number);
	if (edited__MODULE_ID__) {
		return;
	}
	edited__MODULE_ID__ = true;
	col = getCol__MODULE_ID__(row, 2);
	col.innerHTML = (createMonthLink__MODULE_ID__(number, items__MODULE_ID__[number].month) + "/" +
		createDaySelect__MODULE_ID__(number, day));
}

function createEditNameForm__MODULE_ID__(number, name) {
	var html =
		"<input class=\"name_td__MODULE_ID__\" onkeypress=\"if (isEnter__MODULE_ID__(event))" +
		"{setName__MODULE_ID__(" + number + ", event); return false;}\" " +
		"type=text id=name_input__MODULE_ID__ value=\"" + name + "\">";
	return html;
}

function submitPriority__MODULE_ID__(number) {
	var row, col, select, newPriority;
	row = getRow__MODULE_ID__(number);
	col = getCol__MODULE_ID__(row, 0);
	select = document.getElementById("select__MODULE_ID__");
	newPriority = select.options[select.selectedIndex].value;
	setPriority__MODULE_ID__(number, newPriority);
	edited__MODULE_ID__ = false;
}

function editName__MODULE_ID__(number) {
	var row, col, name;
	if (edited__MODULE_ID__) {
		return;
	}
	edited__MODULE_ID__ = true;
	row = getRow__MODULE_ID__(number);
	col = getCol__MODULE_ID__(row, 1);
	name = items__MODULE_ID__[number].name;
	col.innerHTML = createEditNameForm__MODULE_ID__(number, name);
	document.getElementById("name_input__MODULE_ID__").focus();
	document.getElementById("name_input__MODULE_ID__").select();
}

function setName__MODULE_ID__(number) {
	var name, row, col;
	name = document.getElementById("name_input__MODULE_ID__").value;
	if (name === "") {
		name = items__MODULE_ID__[number].name;
	}
	items__MODULE_ID__[number].name = name;
	row = getRow__MODULE_ID__(number);
	col = getCol__MODULE_ID__(row, 1);
	col.innerHTML = createName__MODULE_ID__(number, name);
	saveItems__MODULE_ID__();
	edited__MODULE_ID__ = false;
	return false;
}

function edit__MODULE_ID__() {
	return edited__MODULE_ID__;
}

function isEnter__MODULE_ID__(e) {
	var characterCode;
	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}
	if (characterCode === 13) {
		return true;
	}
	return false;
}

function getTable__MODULE_ID__() {
	return document.getElementById("itemsTable__MODULE_ID__");
}

function init__MODULE_ID__() {
	prefs__MODULE_ID__ = new gadgets.Prefs(__MODULE_ID__);
	edited__MODULE_ID__ = false;
	loadItems__MODULE_ID__();
	if (prefs__MODULE_ID__.getString("sort") === null) {
		prefs__MODULE_ID__.set("sort", "priority");
	}
	createTable__MODULE_ID__();
}

gadgets.util.registerOnLoadHandler(init__MODULE_ID__);